<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<view class="cu-bar bg-white hide" >
			<view class="action">
				<u-icon name="/static/image/invcode.png" size="80"></u-icon>
				<text class="cuIcon-titles text-bold">完善重量信息</text> 
			</view>
		</view>
		<u-form class="form bg-white" style="margin-top: -20px;" :model="model"  ref="uForm" label-position="left">
			<u-form-item label="计划到货重量:" prop="planWeight" label-width="260" required >
				<u-input placeholder="" v-model="model.planWeight" @input="planWeightChange" type="digit"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="建议入库重量:" prop="jyWeight" label-width="260">
				<u-input placeholder="" v-model="model.jyWeight" type="digit" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="确认入库重量:" prop="qrWeight" label-width="260" required >
				<u-input placeholder="请填写确认入库重量" @input="qrWeightChange" v-model="model.qrWeight" type="digit"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="入库仓库:" prop="rkStore" label-width="260" required>
				<js-select v-model="model.rkStore" dict-type="mf_rk_store" placeholder="请选择入库仓库"></js-select>
			</u-form-item>
			<u-form-item label="供方重量:" prop="gfWeight" label-width="260">
				<u-input placeholder="请填写供方重量" v-model="model.gfWeight" type="digit"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="海关重量:" prop="hgWeight" label-width="260">
				<u-input placeholder="请填写海关重量" v-model="model.hgWeight" type="digit"  di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="折算系数:" prop="irate" label-width="260">
				<u-input placeholder="请填写折算系数" v-model="model.irate" type="digit"  di maxlength="64"></u-input>
			</u-form-item>
		</u-form>
		<!-- <view class="form-footer b-btns">
			<view class="footer">
				<u-button class="btn" type="primary" @click="submit" v-if="cstatus!='已推送'">保存</u-button>
			</view>
		</view> -->
		
		<view style="height: 60px;" v-if="cstatus!='已推送'"></view>
		<view class="btn-group cu-bar foot" v-if="cstatus!='已推送'">
			<button class="cu-btn bg-green shadow-blur" @tap="submit()">
				<text class="cuIcon-add"></text> 保存
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model:{
				},
				carType:'',
				carVenSelectList: [],
				cstatus:'',
			}
		},
		onLoad(params){
			this.cstatus=params.cstatus
			this.model = JSON.parse(params.model)
			this.carType  = this.model.hid?this.model.hid.carType:''
			if(this.model.rkStore==null || this.model.rkStore==undefined || this.model.rkStore==''){
				this.model.rkStore='101'
			}
		},
		onShow() {
			
		},
		methods: {
			planWeightChange(e) {
				if (this.carType == 1) {
					if (e > 0) {
						e = -e
					}
				} else {
					if (e < 0) {
						e = -e
					}
				}
				this.model.planWeight = e
				this.$forceUpdate()
			},
			qrWeightChange(e) {
				if (this.carType == 1) {
					if (e > 0) {
						e = -e
					}
				} else {
					if (e < 0) {
						e = -e
					}
				}
				this.model.qrWeight = e
				this.$forceUpdate()
			},
			submit(data, callback) {
				if(this.model.planWeight == null || this.model.planWeight == ''){
					this.$refs.jsError.showError('','请填入计划入库重量！','error');
					return;
				}else if(this.model.qrWeight == null || this.model.qrWeight == ''){
					this.$refs.jsError.showError('','请填入确认入库重量！','error');
					return;
				}else if(this.model.rkStore == null || this.model.rkStore == ''){
					this.$refs.jsError.showError('','请正确选择仓库！','error');
					return;
				}else{
					var data = {
						mfCarplanDhC: JSON.stringify(this.model),
						useStatus: 1
					};
					console.log(data)
					this.$u.api.mfsh.saveDetail(data).then(res => {
						if(res.result == 'true'){
							this.$u.toast(res.message);
							setTimeout(()=>{
								uni.$emit('refreshData');
								uni.navigateBack({
									delta: 1
								})
							},500)
						}else{
							this.$refs.jsError.showError('',res.message,'error');
						}
						
					});
				}
				
			},
		}
	}
</script>
<style scoped>
/* .footer {
	position: fixed;
	left: 0;
	bottom: 20px;
	width: 100%;
	
} */
.hide{
	display: none;
}
.cu-bar {
		min-height: 60px;
	}


	.foot {
		background: #fff;
	}

	.cu-item {
		flex-wrap: wrap;
		padding: 8px 15px !important;
	}

	.title {
		width: 100px;
	}

	.cu-modal-slot {
		margin: 42rpx 32rpx 20rpx 32rpx;
		height: 100vh;
		position: relative;
	}

	.cu-modal-header {
		font-size: 38rpx;
		color: #3d3d3d;
		line-height: 40rpx;
		text-align: left;
		font-weight: 500;
	}

	.button {
		font-size: 32rpx;
		color: #666666;
		line-height: 40rpx;
		padding: 12rpx 40rpx;
		margin-bottom: 20rpx;
		background: #e2e2e2;
		border-radius: 180rpx;
	}

	.button:hover {
		background: #3e97b0;
		color: #ffffff;
	}

	.cu-modal-search-title {
		margin: 32rpx 0rpx 20rpx 0rpx;
		text-align: left;
		font-size: 32rpx;
		color: #999999;
		line-height: 40rpx;
	}

	.cu-dialog {
		background: #ffffff;
	}

	.cu-modal-footer {
		padding: 32rpx 32rpx;
		width: 100%;
	}
	
	.cu-btn {
		font-size: 16px;
		height: 40px;
		width: 50%;
	}

	.bg-confirm {
		background: #3e97b0;
		color: #ffffff;
	}
</style>